<?php
/**
 * User: Administrator
 * Note: 管理员登录日志
 */
namespace Admin\Controller;

class AdminloginController extends BaseController
{
    public function index()
    {
        if (IS_POST) {
            $username   = I('username', '', 'trim');
            $date       = I('date', '', 'trim');
            $page_count = I('limit', '', 'intval');
            $page       = I('page', '', 'intval');
            $map        = array();
            if ($date) {
                list($start_time, $end_time) = explode(' - ', $date);
                $start_time = $start_time?strtotime(trim($start_time)):0;
                $end_time   = $end_time?strtotime(trim($end_time))+24*60*60:0;
                if ($start_time && $end_time) {
                    $map['login_time'] = array(array('egt',$start_time),array('elt',$end_time));
                }
            }
            if ($username) {
                $map['username'] = array('like', '%'.$username.'%');
            }
            $total = M('log_admin')->where($map)->count();
            $limit = ($page - 1)*$page_count.','.$page_count;
            $_list = M('log_admin')->alias('e')
                ->join('LEFT JOIN __MEMBER__ m on m.id=e.uid')
                ->field(array('e.id'=>'id','e.*','m.username'=>'username'))
                ->where($map)
                ->limit($limit)
                ->order('e.id desc')
                ->select();

            foreach ($_list as &$item) {
                $item['login_time'] = date('Y-m-d H:i', $item['login_time']);
            }
            layuiReturn(0, '成功', $_list, $total);
        } else {
            $this->assign('meta_title', '公告管理');
            $this->display();
        }
    }
}
